// 导入api接口
import { selectwarnDetailsList, selectwarnDetailsLists, updateWarn, warnDetailsdownloadExcel } from '@/api/api';
import configJs from '@/utils/configJs';
import { mapGetters, mapState } from 'vuex';
import defaultData from './data';
var data = JSON.parse(JSON.stringify(defaultData))
var adapter = {
	data,
	methods: {
		// ...mapActions(['logOut']),
		/**
		 * 初始化
		 */
		initPage(){
			//还原页面对象
			configJs.revert(data, defaultData);
		},
		initwarnDetailsList(){
			if (!this.$store.getters.pageAuth.authoritySearch) {
				return
			}
			//获取数据
			selectwarnDetailsList().then((res)=>{
				console.log(res.data)
				this.page = res.data
			})
		},
		handleSizeChange(val){
			console.log(val)
		},
		async search(val){
			let ksyjsjtimedata =""
			let yjclsjtimedata =""
			if(this.ksyjsjstarttime && this.ksyjsjendtime){
				ksyjsjtimedata = this.ksyjsjstarttime+"_"+ this.ksyjsjendtime
				console.log(ksyjsjtimedata)
			}
			if(this.yjclsjstarttime && this.yjclsjendtime){
				yjclsjtimedata = this.yjclsjstarttime+"_"+ this.yjclsjendtime
				console.log(yjclsjtimedata)
			}
			let params;
			if(typeof val != 'number' && (val = 1)){
				params={
					ksyjsj:ksyjsjtimedata ==''?'':ksyjsjtimedata,
					yjclsj:yjclsjtimedata ==''?'':yjclsjtimedata,
					operator:this.recordSearchObj[0].operator ==''?'':this.recordSearchObj[0].operator,
					yjcpxm:this.recordSearchObj[0].yjcpxm ==''?'':this.recordSearchObj[0].yjcpxm,
					yjdl:this.recordSearchObj[0].yjdl ==''?'':this.recordSearchObj[0].yjdl,
					yjzl1:this.recordSearchObj[0].yjzl1 ==''?'':this.recordSearchObj[0].yjzl1,
					yjzl2:this.recordSearchObj[0].yjzl2 ==''?'':this.recordSearchObj[0].yjzl2,
					yjxm:this.recordSearchObj[0].yjxm ==''?'':this.recordSearchObj[0].yjxm,
					yjnr:this.recordSearchObj[0].yjnr ==''?'':this.recordSearchObj[0].yjnr,
					yjzt:this.recordSearchObj[0].yjzt ==''?'':this.recordSearchObj[0].yjzt,
					bz:this.recordSearchObj[0].bz ==''?'':this.recordSearchObj[0].bz,
				}
			}else{
				params={
					page:val,
					ksyjsj:ksyjsjtimedata ==''?'':ksyjsjtimedata,
					yjclsj:yjclsjtimedata ==''?'':yjclsjtimedata,
					operator:this.recordSearchObj[0].operator ==''?'':this.recordSearchObj[0].operator,
					yjcpxm:this.recordSearchObj[0].yjcpxm ==''?'':this.recordSearchObj[0].yjcpxm,
					yjdl:this.recordSearchObj[0].yjdl ==''?'':this.recordSearchObj[0].yjdl,
					yjzl1:this.recordSearchObj[0].yjzl1 ==''?'':this.recordSearchObj[0].yjzl1,
					yjzl2:this.recordSearchObj[0].yjzl2 ==''?'':this.recordSearchObj[0].yjzl2,
					yjxm:this.recordSearchObj[0].yjxm ==''?'':this.recordSearchObj[0].yjxm,
					yjnr:this.recordSearchObj[0].yjnr ==''?'':this.recordSearchObj[0].yjnr,
					yjzt:this.recordSearchObj[0].yjzt ==''?'':this.recordSearchObj[0].yjzt,
					bz:this.recordSearchObj[0].bz ==''?'':this.recordSearchObj[0].bz,
				}
			}
			console.log(params)
			selectwarnDetailsLists(params).then((res)=>{
				console.log(res)
				this.page = res.data
			})
		},
		reset(){
			this.recordSearchObj = [{
				operator:"",
				yjcpxm:"",
				yjdl:"",
				yjzl1:"",
				yjzl2:"",
				yjxm:"",
				yjnr:"",
				yjzt:"",
				bz:""
			}]
			this.yjclsjstarttime=''
			this.yjclsjendtime=''
			this.ksyjsjendtime=''
			this.ksyjsjstarttime=''
			this.search()
		},
		//修改预警状态
		save(){
			let id = this.yjztchangeid;
			if(id == ""){
				this.$message({
                    type: 'info',
                    message: `请选择一条预警修改`
                });
			}else{
				console.log(id)
				updateWarn(id).then((res)=>{
					console.log(res)
					if(res.code ==0){
						this.$message({
							type: 'success',
							message: `预警修改成功`
						});
						this.search()
					}
					
				})
			}
		},
		//获取改变的预警状态ID
		yjztchange(id){
			this.yjztchangeid = id;
			// console.log(id)
		},
		//下载
		async exceldownload(){
			warnDetailsdownloadExcel()
		},
		//点击行
		rowClick(row, column, e) {
			
		},
		tabrowstyle({row}){
			console.log(row.yjzt)
			if(row.yjzt =="待处理"){
				return 'background-color:red !important;color:#fff'
			}
		}	
	},
	computed: {
		...mapState({
			supperAdmin: state => state.user.supperAdmin,
			userinfoname:state => state.user
		}),
		...mapGetters(['userPageAuth']),
	}
}
export default adapter
